package com.justgame.project.generator.template.impl;

import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.justgame.project.generator.enums.TemplateType;
import com.justgame.project.generator.properties.GlobalProperties;
import com.justgame.project.generator.properties.TemplateProperties;
import com.justgame.project.generator.template.ITemplateResolve;
import com.justgame.project.generator.utils.NameUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

@Component
public class BasicServiceTemplateResolve implements ITemplateResolve{
    private final TemplateProperties templateProperties;
    private final GlobalProperties globalProperties;

    public BasicServiceTemplateResolve(TemplateProperties templateProperties, GlobalProperties globalProperties) {
        this.templateProperties = templateProperties;
        this.globalProperties = globalProperties;
    }

    @Override
    public TemplateType getType() {
        return TemplateType.BASIC_SERVICE_INTERFACE;
    }

    @Override
    public String getTemplateFilePath() {
        Assert.hasLength(templateProperties.getBasicServiceInterfaceTemplatePath(),"请先配置 Basic Service Interface 模板文件路径");
        return templateProperties.getBasicServiceInterfaceTemplatePath();
    }

    @Override
    public String getOutputFilePath(String tableName) {
        String moduleName = NameUtils.getModuleNameByTableName(tableName);
        String entityName = NameUtils.getEntityNameByTableName(tableName);
        return globalProperties.getProjectPath() + globalProperties.getAfterProjectOperationPath() +
                "/" + NameUtils.formatModuleServiceName(moduleName) + "/src/main/java"+ globalProperties.getOperationPackage() + "/"+ moduleName +
                "/service/basic/" + "Basic" + entityName + "Service" + StringPool.DOT_JAVA;
    }
}
